 package com.springmvc.demo.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.springmvc.demo.mapper.RoleMapper;
import com.springmvc.demo.mapper.UserMapper;
import com.springmvc.demo.mapper.UserRoleMapper;
import com.springmvc.demo.model.Role;
import com.springmvc.demo.model.User;
import com.springmvc.demo.model.UserRole;
import com.springmvc.demo.service.UserService;

@Service
public class UserServiceImpl implements UserService{
	@Autowired
	RoleMapper roleMapper;
	
	@Autowired
	UserRoleMapper userRoleMapper;
	
	@Autowired
	UserMapper userMapper;

	@Override
	public User login(User usr) {
		// TODO Auto-generated method stub
		User u=userMapper.login(usr);
	    if(u!=null)
	    	return u;
	    else
	    	return null;
	}
	

	
	@Override
	public User getUserByUserid(String userid) {
		// TODO Auto-generated method stub
		return userMapper.findUserByUserid(userid);
	}


	@Override
	public List<UserRole> checkUserHasRoles(String userid) {
		// TODO Auto-generated method stub
		return userRoleMapper.userHasRoles(userid);
	}



	@Override
	public List<Role> getRoleList() {
		// TODO Auto-generated method stub
		return roleMapper.listAllRole();
	}



	@Override
	public List<User> getUserList() {
		// TODO Auto-generated method stub
		return userMapper.listAllUser();
	}



	@Override
	public String addUser(User user) {
		// TODO Auto-generated method stub
		
		User u=userMapper.findUserByUserid(user.getUserid());
		if(u!=null) {
			return "用户名已存在！";
		}
		int i=userMapper.insertUser(user);
		if(i>0)
			return "添加成功";
		else
			return "添加失败";
	}




}
